This invention relates to a variable length encoding apparatus used for data compression processing.
The moving picture data compression processing is a typical usage of the conventional variable length encoding apparatus.
In MPEG (Moving Picture Experts Group) standard, which is the international standard of the moving picture data compression, the differential processing with DCT (discrete cosine transform), quantization, and a motion compensation is carried out. In MPEG standard, the motion compensation is processed based on the unit composed of the pixel of 16 in length and 16 in width, which is called a macro block, for improving the compression efficiency.
In MPEG, variable length encoding is processed, however, this variable length encoding is used for decreasing the code length stochastically, so that it is not sure whether the generated encode bit amount is always decreased or not. Moreover, the generated encode bit amount will fluctuate corresponding to the difficulty of the encoding processing such as the moving picture data encoding and the video data encoding.
The fluctuation of this generated encode bit amount is controlled by the buffer model of the decoder. Practically, it is specified by the standard that the input buffer should exist in the ideal decoder when a real-time decode is performed and a system should operate decoding without overflow or underflow to this input buffer. According to the MPEG specification, the generated bit amount fluctuation is accepted if it is within the capacity of the input buffer of the decoder. However, in other words, the encoding apparatus should perform encoding under this limit.
In this way, the variable length encoding is performed in MPEG and the generated encode bit amount should be controlled. Generally, the method for generated encode bit amount control is called the rate control. As a rate control technology, a method for controlling a step in a normal quantization is known, which is disclosed by the Japanese laid open publication Tokkai-Hei 7-107947. Another method for controlling the generated encode bit amount after performing a variable length encoding is known, which is disclosed by the Japanese laid open publication Tokkai-Hei 6-14314.
By the method for enlarging the quantization step, the generated encode bit amount can be decreased to some extent. However, the actual generated encode bit amount is not known until encoding processing actually is performed. This means that the method for controlling the quantization step has a problem of credibility because this method can not forecast the generated encode bit amount practically in advance. When the quantization step is controlled by the macro block unit, the conventional method still has a problem that a picture quality will be deteriorated even for data which will be encoded with high picture quality if it is encoded in a normal encoding method because the above mentioned method should control the upper limit of the generated encode bit amount considering the possible worst condition, which rarely actually occurs. Especially in a real time encoding system, re-encoding processing for re-encoding the encoded data in order to optimize the encoded result is almost impossible, so that there is no way but performing the above mentioned method for ensuring such limit, and the picture quality is deteriorated.
The above mentioned problem will be solved by controlling the bit amount after performing the variable length encoding, however, by the method disclosed in the Japanese laid open publication Tokkai-Hei 6-14314, the hardware scale will be enlarged because the full length of the variable length code should be memorized, in addition, in some cases, the picture quality deterioration by a mismatching of the locally decoded picture and the decoded picture by the decoder can occur in several serial frames. In addition, there is a problem that the picture quality deterioration is concentrated occasionally to a specific macro block, so that the picture quality deterioration is seen remarkably easily.
It is an object of the variable length encoding apparatus of the present invention to solve the above mentioned problem and to provide a control of the upper limit of the generated encode bit amount surely without the remarkable picture quality deterioration in a real time processing.
In order to achieve the above objects, the variable length encoding apparatus of the present invention includes a variable length encoding means for encoding an input data into variable length code processing unit by processing unit, a buffering means for temporarily storing the variable length encoding data processed by the variable length encoding means and a code replacement processing means for replacing the variable length encoding data stored in the buffering means with a prepared short code which code amount is less than that of the variable length encoding data according to the generated code amount of the variable length encoding data.
By the above mentioned embodiment, in the variable length encoding processing, a data which has large code amount per a processing unit can be replaced with a short code according to the necessity, and the encode amount per one processing unit will be decreased, so that the encode bit amount can be controlled surely within the upper limit.
Next, the variable length encoding apparatus further includes a means for setting the upper limit of the generated code amount per one processing unit of the input data, wherein the code replacement processing means comprises a means for replacing the variable length encoding data stored in the buffering means with the prepared short code when the generated code amount of the processing unit of the variable length encoding data exceeds the upper limit, a means for executing no operation of replacing the encoded data when the generated code amount of the processing unit of the variable length encoding data does not exceed the upper limit.
By the above mentioned embodiment, the upper limit of the generated code amount per one processing unit can be controlled flexibly, in the variable length encoding processing, the generated encode bit amount per one processing unit which exceeds the upper limit can be replaced with a short code, so that the encode bit amount can be surely controlled within the upper limit.
Next, it is preferable that the input data is an intraframe compression data or an interframe compression data of a motion picture, and the processing unit is data per one picture of a motion picture.
By the above mentioned embodiment, this invention can be applied to a variable length encoding processing in the motion picture data compression processing, so that this invention can be utilized in a variable length encoding processing in the motion picture data compression processing of MPEG standard , the H.261 standard or the like.
Next, it is preferable that the prepared short code which the code replacement processing means uses at code replacement processing is data leading to the same decoding result as the preceding processed replaced data of the processing unit of the code replacement processing by the code replacement processing means.
By the above mentioned embodiment, when decoding the replaced data, the decoded picture will be the same as the previous picture which has already been decoded previously, so that an observer does not recognize the picture quality deterioration.
Next, it is preferable that the code replacement processing means replaces the input data with the prepared short code input data when the input data is a bidirection prediction encoding picture, and selects the data leading to the same decoding result as either one of an intraframe encoding picture which is preceding at a nearest position in time series, a forward prediction encoding picture which is preceding at a nearest position in time series, an intraframe encoding picture which is following at a nearest position in time series or a forward prediction encoding picture which is following at a nearest position in time series if it is decoded.
By the above mentioned embodiment, a bidirection prediction encoding picture data, which has the necessity of being replaced, can be replaced with the picture data which is the nearly preceding picture or nearly following picture to the replaced picture and which code amount is within the predetermined code amount, so that an observer does not recognize the picture quality deterioration when decoding the motion picture.
Furthermore, at the above data selection, when the data corresponding to the following picture is selected, it preferable that all bidirection prediction encoding pictures between the input data and the selected following picture are replaced with the data leading to the same decoding result as the selected following picture if it is decoded.
By the above mentioned embodiment, in the code replacement processing of the bidirection prediction encoding picture data, picture data following the replaced picture data does not become a picture of the past in the time series, so that an observer does not recognize the picture quality deterioration when decoding to the motion picture because there is no disorder of the picture in time series.
Next, it is preferable that the code replacement processing means replaces the input data with the prepared short code input data when the input data is a forward prediction encoding picture, and selects the data leading to the same decoding result as either one of an intraframe encoding picture which is preceding at a nearest position in time series, a forward prediction encoding picture which is preceding at a nearest position in time series, a forward prediction encoding picture following to the forward prediction encoding picture which is the input data refers the selected preceding picture if it is decoded.
By the above mentioned embodiment, a forward prediction encoding picture data which has necessity to be replaced can be replaced with the picture data which is the nearly preceding picture to the replaced picture and which code amount is within the predetermined code amount, so that an observer does not recognize the picture quality deterioration when decoding to the motion picture. In addition, in the referencing processing of a forward prediction encoding picture following to the previously replaced forward prediction encoding picture, the forward picture is referred so that the replaced forward prediction encoding picture will not be referred in the other picture referencing processing, no problem will occur.